package yt.kpool.adapter;

import android.content.Context;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.math.BigDecimal;
import java.util.List;

import yt.kpool.R;

import yt.kpool.activity.home.HomeSecondAc;
import yt.kpool.activity.home.HomeSecondDetailAc;
import yt.kpool.base.BaseApplication;
import yt.kpool.bean.HomeListBean;
import yt.kpool.bean.MinerModelDetailsBean;
import yt.kpool.network.NetHelperNew;
import yt.kpool.util.Util;
import yt.kpool.util.imageUtil.GlideUtil;

public class SimpleSecondAdapter extends BaseQuickAdapter<MinerModelDetailsBean.DataBean.CoinListBean, BaseViewHolder> {
    private Context context;
    private Double Exchange;
    private int kind;
    private double flash_p=0.00;//电费
    public SimpleSecondAdapter(Context context,@Nullable List<MinerModelDetailsBean.DataBean.CoinListBean> data) {
        super(R.layout.item_second_layout, data);
        this.context=context;

    }

    @Override
    protected void convert(BaseViewHolder helper, final  MinerModelDetailsBean.DataBean.CoinListBean item) {
        Log.d("PPP",helper.getAdapterPosition()+"");
        TextView tv=helper.getView(R.id.tv_vieww);
        if(item.getName()!=null)
        {
           if(helper.getAdapterPosition()== getData().size())
            {
                tv.setVisibility(View.VISIBLE);
            }
            else
            {
                tv.setVisibility(View.GONE);
            }
            GlideUtil.loadImage(context, NetHelperNew.URL + item.getIcon(), (ImageView) helper.getView(R.id.iv_icon), R.mipmap.ic_launcher, R.mipmap.ic_launcher);




            BigDecimal c1 = new BigDecimal(item.getCurrencyPrice());
            BigDecimal c2 = new BigDecimal(Exchange);
            String cp1=c1.multiply(c2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"";



            BigDecimal b1 = new BigDecimal(item.getThroughput());
            BigDecimal b2 = new BigDecimal(cp1);
            String sp1=b1.multiply(b2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"";


            BigDecimal bb1 = new BigDecimal(item.getPower());
            BigDecimal bb2 = new BigDecimal(Util.NMultiplication(0.024+"",flash_p+""));
            String sp2=bb1.multiply(bb2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"";

            helper.setText(R.id.tv_Currency, item.getCurrency().toUpperCase());

            TextView textView=helper.getView(R.id.tv_price);
            BigDecimal bbb1 = new BigDecimal(sp1);
            BigDecimal bbb2 = new BigDecimal(sp2);
            String sp3=bbb1.subtract(bbb2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"";
            TextView tv_d1=helper.getView(R.id.tv_d1);
            helper.setText(R.id.tv_flsahay, item.getThroughput()+" / ");

            if(kind==1)//人民币
            {
                helper.setText(R.id.tv_CurrencyPrice, "¥"+cp1+"/"+"¥"+sp2);
                helper.setText(R.id.tv_datePay, sp1);

                textView.setText("¥"+sp3);
                tv_d1.setText("¥");


            }
            else if (kind==2)//美元
            {
                helper.setText(R.id.tv_CurrencyPrice, "$"+ item.getCurrencyPrice()+"/"+"$"+sp2);
                helper.setText(R.id.tv_datePay, Util.Transformation(sp1));
                textView.setText("$"+Util.Subtraction(Util.Transformation(sp1),sp2));
                tv_d1.setText("$");

            }


            helper.getConvertView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
              context.startActivity(new Intent(context, HomeSecondDetailAc.class));
                }
            });

        }
        else
        {

            helper.setText(R.id.tv_Currency, "");
            helper.setText(R.id.tv_flsahay, "");
            helper.setText(R.id.tv_d1, "");
            helper.setText(R.id.tv_datePay, "");
            helper.setText(R.id.tv_CurrencyPrice, "");
            helper.setText(R.id.tv_price, "");
            tv.setVisibility(View.GONE);
        }

        helper.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HomeSecondDetailAc.start(context,item.getCurrencyID()+"");
            }
        });

    }

    /**
     * 设置电费
     * @param Exchange
     */
    public void setExchange(Double Exchange)
    {
        this.Exchange=Exchange;
    }

    /**
     * 设置币种
     * @param kind
     */
    public void setKind(int kind,double flash_p)
    {
        this.kind=kind;
        this.flash_p=flash_p;

    }




}
